home *** CD-ROM | disk | FTP | other *** search
- #define MACODBC 1
-
- #if ! PPCODBC
- #include "LibraryManager.h"
- #endif
-
- #include <Types.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "sqlext.h"
-
- void quickTest();
-
- #include <OSUtils.h>
-
- main()
- {
- fprintf( stdout, "ear wig oh\n" ); fflush( stdout );
- // SysBeep(10);
-
- #if ! PPCODBC
- InitLibraryManager(0, kCurrentZone, kNormalMemory);
- #endif
-
- quickTest();
-
- #if ! PPCODBC
- CleanupLibraryManager();
- #endif
-
- fprintf( stdout, "cya\n" ); fflush( stdout );
-
- return 0;
- }
-
-
- //____ quickTest stuff _________________________
-
- #include "autotests.h"
-
- BOOL_EXTFUNCDECL_FAR szLogPrintf(lpSERVERINFO lps, BOOL fForce, LPSTR szFmt /*, ...*/)
- {
- #pragma unused(lps)
-
- fprintf( stdout, szFmt );
- fflush( stdout );
-
- return 0;
- }
-
- #include <events.h>
- #include <toolutils.h>
-
- #define KEY_CONTROL 59
- #define KEY_OPTION 58
- #define KEY_SHIFT 56
- #define KEY_COMMAND 55
-
- Boolean KeyIsDown(
- short theKeyCode)
- {
- KeyMap theKeys;
-
- GetKeys(theKeys); /* Get state of each key */
-
- /* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a */
- /* 16-byte (128 bits) array where each bit specifies the start */
- /* of a key (0 = up, 1 = down). We isolate the bit for the */
- /* specified key code by first determining the byte position in */
- /* the KeyMap and then the bit position within that byte. */
- /* Key codes 0-7 are in the first byte (offset 0 from the */
- /* start), codes 8-15 are in the second, etc. The BitTst() trap */
- /* counts bits starting from the high-order bit of the byte. */
- /* For example, for key code 58 (the option key), we look at */
- /* the 8th byte (7 offset from the first byte) and the 5th bit */
- /* within that byte. */
- /* p.s. - key 59 is ? */
-
- return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
- (long) 7 - (theKeyCode % 8) ) );
- }
- #include <String.h>
-
- void
- quickTest()
- {
- SERVERINFO si;
- char buf[ 100 ];
-
- again:
- memset(&si, 0, sizeof(si));
-
- si.hwnd = NULL; //pTestSource->pGrafPort;
- si.henv = NULL;
- si.hdbc = NULL;
-
- strcpy(si.szSource, "");
- printf( "data source: " ); fflush( stdout );
- gets( buf );
- strcpy(si.szValidServer0, buf );
- printf( "login: " ); fflush( stdout );
- gets( buf );
- strcpy(si.szValidLogin0, buf );
- printf( "password: " ); fflush( stdout );
- gets( buf );
- strcpy(si.szValidPassword0, buf);
-
- if ( KeyIsDown( KEY_OPTION ) ) // option
- {
- si.szBuff[0] = 1;
- SysBeep( 10 );
- }
-
- fprintf( stdout, "%s - %s - %s\n", si.szValidServer0, si.szValidLogin0, si.szValidPassword0 ); fflush( stdout );
- // si.rglMask = (UINT) pTestSource->rglMask;
-
- AutoTestFunc(&si);
-
- printf( "again? " ); fflush( stdout );
- gets( buf );
- if ( *buf == 'y' ) { goto again; }
-
- }
-
-
- #if 0
- //____ cursTest stuff _________________________
-
- HENV henv = 0;
- HDBC hdbc = 0;
-
- void
- cc( RETCODE rc, char* fn, HSTMT hstmt = NULL )
- {
- if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO )
- {
- fprintf( stdout, "%s failed (%d)\n", fn, rc );
-
- UCHAR state[6];
- SDWORD nativeErr;
- UCHAR msg[200];
- SWORD msglen;
- RETCODE rc;
-
- for (;;)
- {
- rc = SQLError( henv, hdbc, hstmt, state, & nativeErr, msg, 200, & msglen );
- if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) { break; }
- fprintf( stdout, " %s: %s (%ld)\n", state, msg, nativeErr );
- }
- fflush( stdout );
-
- if ( hdbc )
- {
- SQLDisconnect( hdbc );
- SQLFreeConnect( hdbc );
- }
- if ( henv ) { SQLFreeEnv( henv ); }
- exit( -1 );
- }
- }
-
-
- typedef unsigned char * UCP;
-
- const UDWORD rows = 2;
- const SDWORD fnmmax = 30;
- const SDWORD lnmmax = 30;
-
- void
- cursTest()
- {
- cc( SQLAllocEnv( & henv ), "SQLAllocEnv" );
- cc( SQLAllocConnect( henv, & hdbc ), "SQLAllocConnect" );
-
- #if ! PPCODBC
- cc( SQLSetConnectOption( hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_ODBC ), "SQLSetConnectOption" );
- #endif
- cc( SQLConnect( hdbc, (UCP)"foo Data Source", SQL_NTS, (UCP)"", SQL_NTS, (UCP)"", SQL_NTS ), "SQLConnect" );
-
- HSTMT s1, s2;
- cc( SQLAllocStmt( hdbc, & s1 ), "alloc s1" );
- cc( SQLAllocStmt( hdbc, & s2 ), "alloc s2" );
-
- #if ! PPCODBC // temporarily zap cursor lib stuff on PPC
- cc( SQLSetStmtOption( s1, SQL_CONCURRENCY, SQL_CONCUR_VALUES ), "s1 opt", s1 );
- cc( SQLSetStmtOption( s1, SQL_CURSOR_TYPE, SQL_CURSOR_STATIC ), "s1 opt2", s1 );
- cc( SQLSetStmtOption( s1, SQL_ROWSET_SIZE, rows ), "s1 opt3", s1 );
- cc( SQLSetCursorName( s1, (UCP)"ECURS", SQL_NTS ), "s1 cursnm", s1 );
-
- cc( SQLExecDirect( s1, (UCP)"SELECT FIRST_NAME, LAST_NAME FROM EMPLOYEE", SQL_NTS ),
- "SQLExecDirect", s1 );
-
- UCHAR fnm[ rows ][ fnmmax ], lnm[ rows ][ lnmmax ];
- SDWORD fnmlen[ rows ], lnmlen[ rows ];
- cc( SQLBindCol( s1, 1, SQL_C_CHAR, fnm, fnmmax, fnmlen ), "s1 bind 1", s1 );
- cc( SQLBindCol( s1, 2, SQL_C_CHAR, lnm, lnmmax, lnmlen ), "s1 bind 2", s1 );
-
- UWORD rowstatus[ rows ];
- UDWORD crow;
- cc( SQLExtendedFetch( s1, SQL_FETCH_ABSOLUTE, - rows, & crow, rowstatus ),
- "fetch last", s1 );
-
- while ( crow )
- {
- --crow;
- fprintf( stdout, "%s %s\n", fnm[ crow ], lnm[ crow ] );
- }
- fprintf( stdout, "\n" ); fflush( stdout );
-
- for (;;)
- {
- RETCODE rc = SQLExtendedFetch( s1, SQL_FETCH_PRIOR, 1, & crow, rowstatus );
- if ( rc == SQL_NO_DATA_FOUND ) { break; }
- cc( rc, "fetch previous", s1 );
- while ( crow )
- {
- --crow;
- fprintf( stdout, "%s %s\n", fnm[ crow ], lnm[ crow ] );
- }
- fprintf( stdout, "\n" ); fflush( stdout );
- }
- #endif
-
- cleanup:
- cc( SQLDisconnect( hdbc ), "SQLDisconnect" );
- cc( SQLFreeConnect( hdbc ), "SQLFreeConnect" );
- hdbc = 0;
- cc( SQLFreeEnv( henv ), "SQLFreeEnv" );
- }
-
- #endif //0